package icu.d4peng.basic.http.feign.encoding;

import feign.Client;
import feign.Feign;

import icu.d4peng.basic.http.feign.FeignAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * 数据压缩
 *
 * @author d4peng d4peng@qq.com
 * @date 2023-11-26 15:36:16
 */

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
@ConditionalOnClass(Feign.class)
@ConditionalOnBean(Client.class)
@ConditionalOnProperty(value = "roc.feign.compression.response.enabled", matchIfMissing = false)
// The OK HTTP client uses "transparent" compression.
// If the accept-encoding header is present, it disables transparent compression.
@Conditional(OkHttpFeignClientBeanMissingCondition.class)
@AutoConfigureAfter(FeignAutoConfiguration.class)
public class FeignAcceptGzipEncodingAutoConfiguration {

	@Bean
	public FeignAcceptGzipEncodingInterceptor feignAcceptGzipEncodingInterceptor(
			FeignClientEncodingProperties properties) {
		return new FeignAcceptGzipEncodingInterceptor(properties);
	}

}
